﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;

namespace Ovvio.Business
{
    public class UserPrincipal : IPrincipal
    {
        private UserIdentity _identity;
        private Role _role;
        public UserPrincipal(UserIdentity identity, Role role)
        {
            _identity = identity;
            _role = role;
        }

        #region IPrincipal Members

        public IIdentity Identity
        {
            get { return _identity; }
        }

        public Role Role { get { return _role; } }
        public UserIdentity UserIdentity { get { return _identity; } }

        public bool IsInRole(string role)
        {
            switch (role.ToLower().Trim())
            {
                case "member":
                    return _role == Role.Member;
                case "admin":
                    return _role == Role.Admin;
                default:
                    return _role == Role.Guest;
            }
        }

        #endregion
    }
}
